import { ResPage } from "@/api/interface/index";
import { Notice } from "@/api/interface/noticeManagement";
import { BASE } from "@/api/config/servicePort";
import moment from "moment";
import http from "@/api";

/**
 * @name 公告管理模块
 */
// 获取公告户列表
export const getNoticeList = (params?: object) => {
  if (params && params["created_at"] && params["created_at"].length === 2) {
    params["created_at_after"] = moment(params["created_at"][0]).format("YYYY-MM-DD HH:mm:ss");
    params["created_at_before"] = moment(params["created_at"][1]).format("YYYY-MM-DD HH:mm:ss");
    delete params["created_at"];
  }
  console.log(params);
  return http.get<ResPage<Notice.ResNoticeList>>(BASE + `/notice/`, params); // 正常 post json 请求  ==>  application/json
};
// 删除公告
export const NoticeTerminate = (params: { ids: any[] }) => {
  return http.delete(BASE + `/notice/${params.ids[0]}/`); // 正常 post json 请求  ==>  application/json
};

// 创建公告
export const createNotice = params => {
  return http.post(BASE + `/notice/`, params);
};

// 修改公告
export const modifyNotice = (id, params) => {
  return http.put(BASE + `/notice/${id}/`, params);
};

// 上传文件
export const uploadPdfApi = params => {
  return http.post(BASE + `/file/`, params);
};

// 下载文件
export const downloadPdfApi = params => {
  return http.get(BASE + `/file/${params}/download/`);
};

// 公告详情
export const noticeView = id => {
  return http.get<Notice.ResNoticeList>(BASE + `/notice/${id}/`);
};
